import axios from './eco/base'

/**
 * 功能: 查询自定义表单列表
 * formType 0：目录节点；1：系统模板，2：自定义模板，3：填报表单
 * optionType 当formType=3为填报表单时，操作类型可分为 1：我的活动，2：与我共享，3：我的收藏，4：我为别人填的表单，5：回收站
 */
export const list = (data) => {
  let params = {
    pageNo: 1,
    pageSize: 10,
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/list', params).then(res => {
    return res
  })
}
export const tree = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/tree', params).then(res => {
    return res
  })
}

/**
 * 功能: 添加自定义表单
 */
export const save = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/save', params).then(res => {
    return res
  })
}

/**
 * 功能: 更新自定义表单
 */
export const update = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/update', params).then(res => {
    return res
  })
}

/**
 * 功能: 删除自定义表单
 */
export const del = (data) => {
  return axios.post('/zn-e-library/dataform/delete/' + data.formId).then(res => {
    return res
  })
}

/**
 * 功能: 删除自定义表单
 */
export const publishForm = (data) => {
  return axios.post('/zn-e-library/dataform/publish/' + data.formId).then(res => {
    return res
  })
}
/**
 * 功能: 停止收集表单
 */
export const stopForm = (data) => {
  return axios.post('/zn-e-library/dataform/stop/' + data.formId).then(res => {
    return res
  })
}
/**
 * 功能: 停止收集表单
 */
export const startForm = (data) => {
  return axios.post('/zn-e-library/dataform/start/' + data.formId).then(res => {
    return res
  })
}
/**
 * 功能: 删除后恢复自定义表单
 */
export const recover = (data) => {
  return axios.post('/zn-e-library/dataform/recover/' + data.formId).then(res => {
    return res
  })
}
/**
 * 功能: 永久删除自定义表单
 */
export const foreverDel = (data) => {
  return axios.post('/zn-e-library/dataform/foreverDel/' + data.formId).then(res => {
    return res
  })
}
/**
 * 功能: 自定义表单详情
 */
export const get = (data) => {
  return axios.post('/zn-e-library/dataform/get/' + data).then(res => {
    return res
  })
}
/**
 * 功能: 自定义表单详情-不需要登录
 */
export const noLoginGet = (data) => {
  return axios.post('/zn-e-library/dataform/noLogin/get/' + data).then(res => {
    return res
  })
}

/**
 * 功能: 复制自定义表单
 * formType 1:系统表单；2：个人表单模板；3：个人填报表单
 * formId 表单ID
 */
export const copy = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/copy', params).then(res => {
    return res
  })
}

/**
 * 功能: 创建目录
 * formType 1:系统表单；2：个人表单模板；3：个人填报表单
 * formName 目录名称
 * parentId 父点ID -1：为一级目录
 */
export const saveDirectory = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/saveDirectory', params).then(res => {
    return res
  })
}

/**
 * 功能: 修改目录
 * formName 目录名称
 * formId 目录ID 
 */
export const updateDirectory = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/updateDirectory', params).then(res => {
    return res
  })
}

/**
 * 功能: 移动目录
 * formName 目录名称
 * formId 目录ID 
 */
export const moveTo = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/moveTo', params).then(res => {
    return res
  })
}

/**
 * 功能: 移动目录
 * formName 目录名称
 * formId 目录ID 
 */
export const delDirectory = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataform/deleteDirectory', params).then(res => {
    return res
  })
}
